<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.w3.org/1999/xhtml">

<head>
  <!--/*--> 引入css、jq、layui等样式、js <!--*/-->
  <meta th:include="~{layout/layout_head :: head}">
</head>

<body>
<div class="layui-fluid">
  <div class="layui-row">
    <form class="layui-form">
      <div class="layui-form-item">
        <label for="title" class="layui-form-label">
          <span class="x-red">*</span>标题</label>
        <div class="layui-input-block" style="width: 65%;">
          <input type="text" id="title" name="title" lay-verify="required" autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-form-item">
        <label for="type" class="layui-form-label">
          <span class="x-red">*</span>申请类型</label>
        <div class="layui-input-inline">
          <select id="type" lay-filter="type" name="type" disabled>
            <option value="leaveProcesses">申请请假</option>
          </select>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span class="x-red">*</span>开始时间</label>
        <div class="layui-input-inline">
          <input type="text" class="layui-input" id="startDate" name="startDate" lay-verify="required" placeholder="年-月-日 时-分-秒">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span class="x-red">*</span>结束时间</label>
        <div class="layui-input-inline">
          <input type="text" class="layui-input" id="endDate" name="endDate" lay-verify="required" placeholder="年-月-日 时-分-秒">
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"><span class="x-red">*</span>描述</label>
        <div class="layui-input-block" style="width: 75%;">
          <textarea name="description" placeholder="描述" class="layui-textarea" required lay-verify="required"></textarea>
        </div>
      </div>
      <div class="layui-form-item">
        <label class="layui-form-label"></label>
        <button class="layui-btn" lay-submit lay-filter="add">发起申请</button>
        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="save">暂存申请</button>
      </div>
    </form>
  </div>
</div>
<script>
  layui.use(['form', 'layer', 'laydate'], function () {
    var $ = layui.jquery;
    var form = layui.form,
        laydate = layui.laydate,
        layer = layui.layer;

    //日期范围
    laydate.render({
      elem: '#startDate'
      , type: 'datetime'
    });
    //时间范围
    laydate.render({
      elem: '#endDate'
      , type: 'datetime'
    });

    //监听提交
    form.on('submit(add)', function (data) {
      var pdata = data.field
      pdata.status = '1'
      //发异步，把数据提交给
      $.post({
        data: pdata,
        url: '/user/applyLeave',
        success: function (data) {
          layer.msg(data.message)
          if (data.code == 0) {
            window.setTimeout(function () {
              var index = parent.layer.getFrameIndex(window.name);
              //关闭当前frame
              parent.layer.close(index);
            }, 1500)
          }
        }
      })
      return false;
    });

    //监听提交
    form.on('submit(save)', function (data) {
      var pdata = data.field
      pdata.status = '0'
      //发异步，把数据提交给
      $.post({
        data: pdata,
        url: '/user/applyLeave',
        success: function (data) {
          layer.msg(data.message)
          // 获得frame索引
          var index = parent.layer.getFrameIndex(window.name);
          window.setTimeout(function () {
            //关闭当前frame
            parent.layer.close(index);
          }, 500)
        }
      })
      return false;
    });
  });
</script>
</body>

</html>
